<template>
  <div>
  	<h3>名称: {{title}}</h3>
  	<el-divider></el-divider>
    <el-form :inline="true" :model="formInline" class="demo-ruleForm">
    	所有合作商同步<br><br>
    	<el-form-item>
	    	<el-button v-if="showBtn0"  type="primary" @click="onSubmit0">同步所有合作商</el-button>
	  	</el-form-item>

		<el-divider></el-divider>

		选择合作商同步<br><br>
	  	<el-form-item label="合作商编号">
	    	<el-input v-model="formInline.supplierNumber" placeholder="输入合作商编码"></el-input>
	  	</el-form-item>
	  	<el-form-item>
	    	<el-button v-if="showBtn1"  type="primary" @click="onSubmit1">同步</el-button>
	  	</el-form-item>
	  	
	  	<el-divider></el-divider>

		按商品同步<br><br>
		<el-form-item label="商品ID">
	    	<el-input v-model="formInline.goodsIds" style="width:500px" placeholder="多个逗号隔开"></el-input>
	  	</el-form-item>
	  	<br>
	  	<el-form-item label="合作商编码">
	    	<el-input v-model="formInline.supplierNumber" placeholder="合作商编码"></el-input>
	  	</el-form-item>
	  	<el-form-item label="上下架状态">
	    	<el-input v-model="formInline.isPubLish" placeholder="1：上架，0：下架"></el-input>
	  	</el-form-item>
	  	<el-form-item label="是否盛星">
	    	<el-input v-model="formInline.isSx" placeholder="1：盛星，2：非药品"></el-input>
	  	</el-form-item>
	  	<el-form-item>
	    	<el-button v-if="showBtn2"  type="primary" @click="onSubmit2">同步</el-button>
	  	</el-form-item>

	</el-form>
  </div>
</template>

<script>
import apiRedoReportLog from "@/api/logManage/redoReportLog";
import { confirm } from "@/utils/index";
export default {
  name: "redoReportLogEsForGoods",
  props:{
        title: { //父组件 查询对象
          type: String,
          default: ""
        }
  },
  data() {
    return { 
      formInline:{
      	supplierNumber:'',
      	goodsIds:'',
      	isPubLish:'',
      	isSx:'',
      },
      submitData:{}, 
      showBtn0:true,
      showBtn1:true,
      showBtn2:true
    };
  },
  methods: {
  	onSubmit0(){
  		confirm("是否同步所有合作商库存?").then(res=>{
  			this.showBtn0 = false
		    setTimeout(() => {
		        this.showBtn0 = true
		    },800)	
		    this.submitData = {
		    	msgType:'syncToEs'
		    }
		    this.doSubmit()
  		})
    },
    onSubmit1(){
    	if(!this.formInline.supplierNumber){
    		this.$message({ type: "error", message: "请输入合作商" });
    		return
    	}
    	this.showBtn1 = false
	    setTimeout(() => {
	        this.showBtn1 = true
	    },800)
	    this.submitData = {
	    	msgType:'syncToEs',
	    	msgContent:{
	    		supplierNumber:this.formInline.supplierNumber
	    	}
	    }
	    this.doSubmit()
    },
    onSubmit2(){
		if(!this.formInline.supplierNumber){
    		this.$message({ type: "error", message: "请输入合作商" });
    		return
    	}
    	if(!this.formInline.goodsIds){
    		this.$message({ type: "error", message: "请输入商品id，多个逗号隔开" });
    		return
    	}
    	if(!this.formInline.isPubLish){
    		this.$message({ type: "error", message: "请输入上下架状态" });
    		return
    	}
    	if(!this.formInline.isSx){
    		this.$message({ type: "error", message: "请输入是否盛星" });
    		return
    	}
    	this.showBtn2 = false
	    setTimeout(() => {
	        this.showBtn2 = true
	    },800)
	    this.submitData = {
	    	msgType:'publichGoods',
	    	msgContent:this.formInline
	    }
	    this.doSubmit()
    },
    doSubmit(){
    	this.submitData.msgContent = JSON.stringify(this.submitData.msgContent)
    	apiRedoReportLog.syncES(this.submitData).then(res=>{
    		this.$message({ type: "success", message: "已提交同步" });
    	})
    }
  }
};
</script>
